package com.qianclass.talklive.app.activity;

import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.qianclass.talklive.app.utils.Constant;

/**
 * Created by iTgoyo
 */
public class BaseActivity extends FragmentActivity {

    public SharedPreferences mSharedPreferences;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mSharedPreferences = getSharedPreferences("config",MODE_PRIVATE);

        ActivityManager activityManager=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        String activityName = activityManager.getRunningTasks(1).get(0).topActivity.getClassName();

        TalkApplication.addDestoryActivity(this, activityName);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onUserInteraction(view);
        }
    };

    public View.OnClickListener getViewClickListener(){
        return onClickListener;
    }

    public void onUserInteraction(View view){

    }

    public void saveUser(String username,String pwd){
        mSharedPreferences.edit()
                .putString(Constant.SP_KEY_USERNAME,username)
                .putString(Constant.SP_KEY_PWD,pwd)
                .commit();
    }

    public String getUserInfoName(){
        return mSharedPreferences.getString(Constant.SP_KEY_USERNAME,"");
    }
    public String getUserPwd(){
        return mSharedPreferences.getString(Constant.SP_KEY_PWD,"");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
